package com.haizhi.crm.api.controller.sys.message;

import com.haizhi.crm.api.constant.MediaType;
import com.haizhi.crm.common.model.Response;
import com.haizhi.crm.sys.message.model.MessageCategoryVo;
import com.haizhi.crm.sys.message.service.MessageCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by wangshan on 2018/5/15.
 */
@Api(description = "[系统-消息分类]消息分类增删改查" )
@RestController
@RequestMapping("/message/category" )
public class MessageCategoryController {

    @Autowired
    private MessageCategoryService messageCategoryService;

    @ApiOperation(value = "获取消息分类列表", notes = "输入：无" )
    @GetMapping("/list" )
    public Response query() {
        List<MessageCategoryVo> messageCategoryVos = messageCategoryService.query();
        return Response.success(messageCategoryVos);
    }

    @ApiOperation(value = "更新消息分类", notes = "输入：messageCategoryVos" )
    @PostMapping(path = "/upsert", consumes = MediaType.APP_JSON, produces = MediaType.APP_JSON)
    public Response saveOrUpdate(@RequestBody List<MessageCategoryVo> messageCategoryVos) {
        messageCategoryService.saveOrUpdate(messageCategoryVos);
        return Response.success();
    }

    @ApiOperation(value = "保存消息分类", notes = "输入：messageCategoryVos" )
    @PostMapping(path = "/save", consumes = MediaType.APP_JSON, produces = MediaType.APP_JSON)
    public Response save(@RequestBody List<MessageCategoryVo> messageCategoryVos) {
        messageCategoryService.saveOrUpdate(messageCategoryVos);
        return Response.success();
    }

    @ApiOperation(value = "删除消息分类", notes = "输入：无" )
    @DeleteMapping(path = "/delete" )
    public Response delete() {
        messageCategoryService.deleteAll();
        return Response.success();
    }


}
